/** * @Description: * @author 赵文龙 * @date $ */
<template>
  <main class="login-form-box">
    <van-form class="login-form" @submit="onSubmit">
      <img src="@/assets/home/logo.png" alt="" class="logo" />
      <van-cell-group inset>
        <van-field
          v-model="formState.username"
          :border="false"
          name=""
          label=""
          placeholder="请输入账户"
          maxlength="24"
          autocomplete="off"
        >
          <template #left-icon>
            <img class="left-icon" src="@/assets/huiyuan.png" alt="" />
          </template>
        </van-field>
        <van-field
          v-model="formState.password"
          :border="false"
          :type="!eyeStatus ? 'password' : 'text'"
          name=""
          label=""
          maxlength="24"
          placeholder="请输入密码"
          autocomplete="off"
        >
          <template #left-icon>
            <img
              class="left-icon"
              src="@/assets/login_ic_password.png"
              alt=""
            />
          </template>
          <template #right-icon>
            <img
              v-if="eyeStatus"
              class="right-icon"
              src="@/assets/login_ic_visible.png"
              alt=""
              @click="swtichEye(false)"
            />
            <img
              v-else
              class="right-icon"
              src="@/assets/login_ic_invisible.png"
              alt=""
              @click="swtichEye(true)"
            />
          </template>
        </van-field>
      </van-cell-group>
      <div @click="toReset" class="reset-btn">忘记密码</div>
      <div style="margin-top: 76px">
        <van-button
          round
          block
          type="primary"
          native-type="submit"
          class="login-btn"
          >登录</van-button
        >
      </div>
    </van-form>
    <!-- <div v-else class="shop-box">
      <img src="@/assets/home/logo.png" alt="" class="logo" />
      <van-field
        v-model="shop"
        is-link
        readonly
        name="picker"
        placeholder="请选择门店"
        @click="showPicker = true"
      />
      <van-popup v-model:show="showPicker" position="bottom">
        <van-picker
          :columns="shopList"
          @confirm="onConfirm"
          @cancel="showPicker = false"
        />
      </van-popup>

      <van-button
        round
        block
        type="primary"
        native-type="submit"
        class="comfirm-btn"
        @click="selectShop"
        >确认</van-button
      >
    </div> -->

    <!-- <div class="tip-box">
      <van-checkbox v-model="formState.checked" checked-color="#fedc00">
        登录即表示同意<span class="tip">《商户协议》</span></van-checkbox
      >
    </div> -->
  </main>
</template>

<script setup>
import { GetParam } from "@/utils/tools";
import { useStoreUser } from "@/store";
import {
  postMpAuthLogin,
  postAgentAuthLogin,
  postMpShopList,
  postMpShopSwitch,
  postAgentUserInfo,
  postAgentUserWallet,
} from "@/api";
import { Notify } from "vant";
const storeUser = useStoreUser();
const router = useRouter();
const step = ref(1);
const formState = reactive({
  username: "",
  password: "",
  checked: true,
  // username: 'admin',
  // password: 'admin',
});
const eyeStatus = ref(false);
const resetPwdRef = ref(null);

function swtichEye(status) {
  eyeStatus.value = status;
}
const shopList = ref([
  // {
  //   text: 1221,
  //   key: 1,
  // },
  // {
  //   text: 222,
  //   key: 2,
  // },
  // {
  //   text: 33,
  //   key: 3,
  // },
]);
const onSubmit = () => {
  // if (!formState.checked) {
  //   Notify({ type: "danger", message: "请先勾选商户协议" });
  //   return;
  // }
  // 线上环境正式使用
  const openId = GetParam(window.location.href, "openId");
  // 本地模拟openId
  // const openId = 111;
  const { password, username } = formState;
  postAgentAuthLogin({
    openId: openId || username,
    password,
    username,
  }).then(async (res) => {
    const { loginUser, multipleShopFlag } = res.data;
    storeUser.dlsToken = loginUser.token;
    const res1 = await postAgentUserInfo();
    const res2 = await postAgentUserWallet();
    storeUser.dlsUserInfo = {
      ...res1.data,
      ...res2.data,
    };
    router.push({
      path: "/",
    });
    // if (!multipleShopFlag) {
    //   router.push({
    //     path: "/",
    //   });
    // } else {
    //   step.value = 2;
    //   postMpShopList().then((res1) => {
    //     shopList.value = res1.data?.map((item) => {
    //       return {
    //         ...item,
    //         text: item.name,
    //         key: item.id,
    //       };
    //     });
    //     console.log(" shopList.value", shopList.value);
    //   });
    // }
  });

  // storeUser.dlsToken = "121";
  // router.push({
  //   path: "/",
  // });
};
const shop = ref("");
const shopId = ref("");
const showPicker = ref(false);
const onConfirm = (obj) => {
  console.log("obj", obj);
  shop.value = obj.text;
  shopId.value = obj.key;
  console.log("shop", shop);
  showPicker.value = false;
};
const selectShop = () => {
  if (!shopId.value) {
    Notify({ type: "danger", message: "请选择商铺" });
    return;
  }
  postMpShopSwitch({
    id: shopId.value,
  }).then((res) => {
    router.push({
      path: "/",
    });
  });
};
const toReset = () => {
  router.push({
    path: "/reset/pwd",
  });
};
</script>

<style scoped lang="less">
.login-form-box {
  background: #fff;
  height: 100%;
  width: 100%;
  position: relative;

  :deep(.login-form) {
    position: absolute;
    top: 50px;
    // transform: translateY(-50%);
    padding: 0 60px;
    width: 100%;
    .logo {
      // position: absolute;
      // left: 50%;
      // top: -80px;
      // transform: translate(-50%, -100%);
      display: block;
      width: 200px;
      height: 200px;
      border-radius: 50%;
      margin: 0 auto 76px;

      // background: #ccc;
    }
    .left-icon {
      width: 48px;
      height: 48px;
      margin-right: 24px;
    }
    .right-icon {
      width: 48px;
      height: 48px;
    }
    .van-cell-group {
      background: transparent;
      margin: 0;
    }
    .van-cell {
      background: #fff;
      // border-radius: 44px;
      // margin-bottom: 16px;
      border-radius: 10px;
      margin-bottom: 36px;
      align-items: center;
      padding: 0;
      padding-bottom: 45px;
      font-size: 32px;
      border-bottom: 1px solid #eaecee;
    }
    .van-field__left-icon,
    .van-field__right-icon {
      display: flex;
      margin-right: 0;
    }
    .van-field__body {
      // height: 25px;
      height: 50px;
    }
    .iconfont {
      font-size: 40px;
    }
  }
}
.login-bg {
  height: 610px;
  // background: url('/src/assets/images/login_back.png') no-repeat;
  background-size: 100%;
  margin-bottom: 48px;
  overflow: hidden;

  .login-icon {
    display: inline-block;
    width: 100%;
  }
}
.login-btn {
  width: 100%;
  // margin: 0 auto;
  height: 88px;
  box-shadow: 0px 2px 40px 0px rgba(255, 255, 255, 0.8);
  border-radius: 40px;
  background: #fedc00;
  color: #000;
  font-weight: 600;
  :deep(.van-button__text) {
    font-size: 30px;
  }
}
.shop-box {
  display: flex;
  flex-direction: column;
  margin: 0 50px;
  padding: 30vh 0;
  // position: relative;
  .logo {
    // position: absolute;
    // left: 50%;
    // top: -80px;
    // transform: translate(-50%, -100%);
    width: 150px;
    height: 150px;
    border-radius: 50%;
    margin: 0 auto;
    margin-bottom: 30px;
    // background: #ccc;
  }
  .comfirm-btn {
    margin: 50px auto;
    width: 80%;
    font-weight: 600;
    font-size: 36px;
    color: #151515;
  }
}
.reset-btn {
  // margin: 0 50px;
  font-size: 26px;
  color: #fedc00;
  text-align: right;
  font-size: 28px;
  color: #333333;
  line-height: 40px;
  font-style: normal;
  text-decoration-line: underline;
}
.tip-box {
  position: absolute;
  bottom: 50px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 24px;
  width: max-content;
  :deep(.van-checkbox__label) {
    font-size: 26px;
  }
  .tip {
    color: #f5af3e;
  }
}
</style>
